<template>
  <el-dialog
    :title="form.id?'编辑':'新增'"
    :visible.sync="dialogVisible"
    :before-close="close"
    width="40%"
  >
    <el-form label-width="100px">
      <el-form-item label="任务名称">
        <el-input v-model="form.taskName" size="mini" placeholder="请输入" />
      </el-form-item>
      <el-form-item label="可获积分">
        <el-input v-model="form.taskName" size="mini" placeholder="请输入" />
      </el-form-item>
      <el-form-item label="每日次数上限">
        <el-radio-group v-model="form.dailyCapIndicator">
          <el-radio label="0">不限</el-radio>
          <el-radio label="1">限制</el-radio>
        </el-radio-group>
        <el-input
          style="margin-left: 8px;width: 100px;"
          size="mini"
          placeholder="请输入"
          v-model="form.dailyCap"
        />次
      </el-form-item>
      <el-form-item label="任务有效期">
        <el-radio-group v-model="form.taskValidityPeriod">
          <el-radio label="0">不限</el-radio>
          <el-radio label="1">自定义</el-radio>
        </el-radio-group>
        <el-date-picker
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          size="mini"
          style="margin-left: 8px;"
          value-format="yyyy-MM-dd"
          v-model="taskTime"
          @change="taskTimeChange"
        />
      </el-form-item>
      <el-form-item label="任务状态">
        <el-radio-group v-model="form.status">
          <el-radio :label="1">启用</el-radio>
          <el-radio :label="0">停用</el-radio>
        </el-radio-group>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button type="primary" @click="confirm">确 定</el-button>
      <el-button @click="close">取 消</el-button>
    </span>
  </el-dialog>
</template>
<script>
import { add, edit } from '@/api/cadreBusiness/IntegralSettings'
export default {
  data () {
    return {
      dialogVisible: false,
      form: {},
      taskTime: []
    }
  },
  methods: {
    open (row) {
      this.form = { ...row }
      if (row) {
        this.taskName = [row.startTime, row.endTime]
      }
      this.dialogVisible = true
    },
    confirm () {
      let submitForm = add
      if (this.form.id) {
        submitForm = edit
      }
      submitForm(this.form).then((res) => {
        this.$message.success('保存成功')
        this.$emit('getData')
        this.close()
      })
    },
    taskTimeChange (val) {
      this.form.startTime = val[0]
      this.form.endTime = val[1]
    },
    close () {
      this.form = {}
      this.taskTime = []
      this.dialogVisible = false
    }
  }
}
</script>
<style lang="scss" scoped>
  .titleStyle {
    font-weight: 600;
    height: 35px;
    line-height: 35px;
    padding-left: 10px;
    padding-right: 10px;
    margin-bottom: 8px;
    background-color: #d8eff9;
    display: flex;
    justify-content: space-between;
  }
  .upload-demo {
    display: inline-block !important;
    margin-left: 16px;
  }
</style>
